package com.qk.controller;

import com.qk.commom.PageResult;
import com.qk.commom.Result;
import com.qk.entity.Activity;
import com.qk.service.ActivityService;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ActivityController {
    @Autowired
    private ActivityService activityService;
    @GetMapping("/activities")
    public Result selectlist(Integer channel, Integer type, Integer status,
                             @RequestParam(defaultValue = "1") Integer page,
                             @RequestParam(defaultValue = "10") Integer pageSize){
        PageResult<Activity> activityList= activityService.select(channel,type,status,page,pageSize);
        return Result.success(activityList);
    }
    @DeleteMapping("/activities/{id}")
    public Result deleteActivity(@PathVariable Integer id){
        activityService.delete(id);
        return Result.success();
    }
    @PostMapping("/activities")
    public Result addActivity(@RequestBody Activity activity){
        activityService.add(activity);
        return Result.success();
    }
    @GetMapping("/activities/{id}")
    public Result findActivityById(@PathVariable Integer id){
        Activity activity= activityService.find(id);
        return Result.success(activity);
    }
    @PutMapping("/activities")
    public Result updateActivity(@RequestBody Activity activity){
        activityService.update(activity);
        return Result.success();
    }
    @GetMapping("/activities/type/{type}")
    public Result findByType(@PathVariable Integer type){
        List<Activity> activityList= activityService.findByType(type);
        return Result.success(activityList);
    }
}
